import vnode from "./vnode";
export function h(sel, data, val){
    if(!sel){
        return ;
    }
    let my_sel = sel,my_data = {},my_val,children;
    if(val){  //传3个参数的时候
        if(Object.prototype.toString.call(data) !== "[object Object]") throw new Error('第二个参数应该为对象')
        my_data = data;
        let val_str = Object.prototype.toString.call(val);
        if(val_str === "[object String]" || val_str === "[object Number]"){
            my_val = val;
        }else if(val_str === "[object Array]"){
            children = [];
            val.forEach(item => {
                // if(Object.prototype.toString.call(item) !== "[object Object]"){
                //     throw new Error('第三个参数数组中类型错误');
                // }
                children.push(item);
            });
        }else if(val_str === "[object Object]" && val.sel){
            children = [];
            children.push(val);
        }else{
            throw new Error('第三个参数类型错误');
        }

    }else if(data){  //传2个参数的时候
        return h(sel,{},data);
    }
    // throw new Error('ceshi')
    return vnode(my_sel, my_data, my_val,undefined, children);
}